***********************************************
*Figure 3: Share of migrating population, 1990*
***********************************************

return clear
capture project, doinfo
if (_rc==0 & !mi(r(pname))) global root `r(pdir)'  // run using -project-
else {  // running directly

	global root "$raw_data_geo/geo_cz1990_creation"

	cap program drop project
	program define project
		di "Project is disabled, skipping project command. (To re-enable, run -{stata program drop project}-)"
	end
	
}

* Specify subdirectories
global raw "$root/raw_data/cz1990"
global out "$root/geo_templates/cz1990"
global test "$root/tests/cz1990"
* Add utility programs to path
adopath ++ "$root/util"
*State lines
project, original("$root/geo_templates/state/state_coords_clean.dta") preserve
copy "$root/geo_templates/state/state_coords_clean.dta" "$out/state_coords_clean.dta", replace


use "$clean_data_lmarket/czone1990_MigrationFlows.dta", clear

*Share of migrants
gen share_migrants = ipums_migrant_a19_64_1990/ipums_pop_a19_64_1990*100

*Share of migrant-students
gen share_student_migrants = ipums_migrant_sc_a19_64_1990/ipums_pop_sc_a19_64_1990*100

*Share of migrant-non-students
gen share_non_student_migrants = (ipums_migrant_a19_64_1990-ipums_migrant_sc_a19_64_1990)/(ipums_pop_a19_64_1990-ipums_pop_sc_a19_64_1990)*100

su share_migrants share_student_migrants share_non_student_migrants [w=ipums_pop_1990]

keep czone share*

rename czone cz
merge n:1 cz using "$out/cz1990_database.dta", keep(3) nogenerate

*Panel A: Non-student migrants
maptile share_non_student_migrants, conus geo(cz1990) stateoutline(medium) geofolder($out) rangecolor(ebblue*.01 ebblue*2) ///
		cutvalues(10 15 20 25 30 35 40 45)   ///
		twopt(title("", size(medium)) legend(position(5) ring(0) size(medium) symysize(*.5) symxsize(*.5) order(10 "{&ge}45.0" 9 "40.0-44.9" 8 "35.0-39.9"  7 "30.0-34.9"  6 "25.0-29.9" 5 "20.0-25.9" 4 "15.0-19.9" 3 "10.0-14.9" 2 "<10.0")) name(exposure_to_robots, replace)) 
graph export "$figures_appendix/Figure A2a.png", replace

*Panel B: Student migrants
maptile share_student_migrants, conus geo(cz1990) stateoutline(medium) geofolder($out) rangecolor(ebblue*.01 ebblue*2) ///
		cutvalues(10 15 20 25 30 35 40 45)   ///
		twopt(title("", size(medium)) legend(position(5) ring(0) size(medium) symysize(*.5) symxsize(*.5) order(10 "{&ge}45.0" 9 "40.0-44.9" 8 "35.0-39.9"  7 "30.0-34.9"  6 "25.0-29.9" 5 "20.0-25.9" 4 "15.0-19.9" 3 "10.0-14.9" 2 "<10.0")) name(exposure_to_robots, replace)) 
graph export "$figures_appendix/Figure A2b.png", replace
